#include <string.h>
#include <malloc.h>
#include <iostream.h>
#include <conio.h>
typedef struct node
{  char n[20];//姓名
    char wid[20];//工作证号
    char sex[5];
    char tel[10];
    char ID[20];
    char position[20];//职务
    char salary[10];
    char birth[20];
    char depart[20];//部门
    char addr[35];
    struct node *next;
}NODE;

class employee
{
private:
    NODE *p;
    NODE *q;
    NODE *t;
public:
    employee(NODE *m);
    void add();
    void printall();
    void print();
    void deleteall();
    void edit();
    void del();
};
employee::employee(NODE *m)
{ t=p=m;
}
void employee::del()
{ NODE *k;
    k=new NODE;
    k=p=q;
    char n[20];
    cout<<"请输入工作证号:"<<endl;
    cin>>n;
    while (p!=t&&(strcmp(p->wid,n)!=0)!=0)
    {k=p;
        p=p->next;
    }
    if (p==t)
    {cout<<"查无此人!!"<<endl;
    }
    else
    {if (p==q)
            q=q->next;
        else
            k->next=p->next;
        free(p);
    }
}
void employee::print()
{ p=q;
    char n[20];
    cout<<"请输入工作证号:"<<endl;
    cin>>n;
    while (p!=t&&(strcmp(p->wid,n)!=0)!=0)
    {p=p->next;
    }
    if (p==t)
    {cout<<"查无此人!!"<<endl;
    }
    else
    { cout<<"姓名:"<<p->n<<endl;
        cout<<"工作证号:"<<p->wid<<endl;
        cout<<"性别:"<<p->sex<<endl;
        cout<<"家庭电话:"<<p->tel<<endl;
        cout<<"身份证号:"<<p->ID<<endl;
        cout<<"职务:"<<p->position<<endl;
        cout<<"薪水:"<<p->salary<<endl;
        cout<<"生日:"<<p->birth<<endl;
        cout<<"部门:"<<p->depart<<endl;
        cout<<"家庭住址:"<<p->addr<<endl;
    }
    cout<<"按任意键返回!!"<<endl;
}
void employee::edit()
{
    p=q;
    char n[20];
    cout<<"请输入员工作证号:"<<endl;
    cin>>n;
    while (p!=t&&(strcmp(p->wid,n)!=0)!=0)
    {p=p->next;
    }
    if (p==t)
    {cout<<"查无此人!!"<<endl;
    }
    else
    {cout<<"姓名";
        cin>>p->n;
        cout<<"工作证号:";
        cin>>p->wid;
        cout<<"性别:";
        cin>>p->sex;
        cout<<"家庭电话:";
        cin>>p->tel;
        cout<<"身份证号:";
        cin>>p->ID;
        cout<<"职务:";
        cin>>p->position;
        cout<<"薪水:";
        cin>>p->salary;
        cout<<"生日:";
        cin>>p->birth;

    }
    cout<<"按任意键返回!!"<<endl;
}
void employee::add()
{
    q= new NODE;
    q->next=p;
    p=q;
    cout<<"姓名:";
    cin>>q->n;
    cout<<"工作证号:";
    cin>>q->wid;
    cout<<"性别:";
    cin>>q->sex;
    cout<<"家庭电话:";
    cin>>q->tel;
    cout<<"身份证号:";
    cin>>q->ID;
    cout<<"职务:";
    cin>>q->position;
    cout<<"薪水:";
    cin>>q->salary;
    cout<<"生日:";
    cin>>q->birth;
    cout<<"家庭住址:";
    cin>>q->addr;
    cout<<"部门:";
    cin>>q->depart;
    cout<<"按任意键返回!!"<<endl;

}
void employee::printall()
{
    p=q;
    while (q!=t)
    {
        cout<<"姓名:"<<q->n<<endl;
        cout<<"工作证号:"<<q->wid<<endl;
        cout<<"性别:"<<q->sex<<endl;
        cout<<"家庭电话:"<<q->tel<<endl;
        cout<<"身份证号:"<<q->ID<<endl;
        cout<<"职务:"<<q->position<<endl;
        cout<<"薪水:"<<q->salary<<endl;
        cout<<"生日:"<<q->birth<<endl;
        cout<<"家庭住址:"<<q->addr<<endl;
        cout<<"部门:"<<q->depart<<endl;
        q=q->next;
        // getch();
    }
    q=p;
}
void employee::deleteall()
{

    while (q!=t)
    {p=q;
        q=q->next;
        free(p);
    }
    cout<<"所有信息已删除！" ;
}

void display()
{


    cout<<"\n  1:增加一个新成员！"<<endl;
    cout<<"\n  2:修改成员信息！"<<endl;
    cout<<"\n  3:查找成员信息！"<<endl;
    cout<<"\n  4:显示所有成员信息！"<<endl;
    cout<<"\n  5:删除成员信息！"<<endl;
    cout<<"\n  6:删除所有成员信息！"<<endl;
    cout<<"\n  7:退出！"<<endl;

}
void main()
{
    NODE *pa;
    char i;
    pa=(NODE*)malloc(sizeof(struct node));
    display();
    employee a(pa);
    while(i=getch())
    {
        switch(i)
        {
            case'1':a.add();getch();display();break;
            case'2':a.edit();getch();display();break;
            case'3':a.print();getch();display();break;
            case'4':a.printall();getch();display();break;
            case'5':a.del();getch();display();break;
            case'6':a.deleteall();getch();display();break;
            case'7':cout<<""<<endl;break;
        }
    }
}
